(require 'completion)
(require 'find-all-file)
(require 'workspace-model)
(defvar *postfix-list* '(".as"))

(defvar as-completion-key-map (make-keymap))
(defvar *key-map* '("var" "function" "return" "public" "private" "import" "class"
		    "String" "int" "const" "Boolean" "Array"))

(defun override-tab ()
  "binding tab with expand and indent-according-to-mode"
  (interactive)
  (let ((point (point)))
    (indent-according-to-mode)
    (when (equal point (point))
      (expand *key-map*))))

(define-key as-completion-key-map "TAB" 'override-tab)
(global-set-key (kbd "C-x C-g") 'search-as-file)


(defun setup-workspace (directory)
  (interactive "Dworkspace path: ")
  (import-as-files directory *postfix-list*))

(define-minor-mode as-completion-mode
  "use tab to complete word."
  :global nil
  :lighter " as-complete"
  :keymap as-completion-key-map)

(defun test ()
  (interactive 
   (intern (completing-read "as:" '("a" "ab") ))))

(defun search-as-file (class-name)
  (interactive 
   (intern (completing-read "Class name: " (get-class-names)))
  (find-as-file class-name)))



(provide 'emacs-as-completion)